Skip to content

Comments

fix: isolate concurrent builds via build_id namespace on git resources#2

Merged
AbirAbbas merged 3 commits intomainfrom
fix/concurrent-build-isolation
Feb 18, 2026
Merged

fix: isolate concurrent builds via build_id namespace on git resources#2
AbirAbbas merged 3 commits intomainfrom
fix/concurrent-build-isolation

Conversation

@AbirAbbas
Copy link
Collaborator

Summary

  • Concurrent build() calls on the same repository collide on shared git resources (integration branch, issue branches, worktree dirs), with the second build silently destroying the first's in-progress work
  • Generate a short build_id (8 hex chars) at the start of build() and thread it through the pipeline so all per-build git resources are uniquely namespaced
  • All new parameters default to "" — fully backward compatible

What Was Broken

When two builds run simultaneously on the same repo, they share:

  1. Integration branchfeature/<goal-slug>: second build fails or hijacks the first's branch
  2. Issue branchesissue/<NN>-<name>: workspace setup agent explicitly deletes existing branches before recreating, silently destroying the other build's committed work
  3. Worktree dirs.worktrees/issue-<NN>-<name>/: same filesystem collision

Changes Made

All git resources are now namespaced by build_id:

  • Integration branch: feature/<build_id>-<goal-slug>
  • Issue branches: issue/<build_id>-<NN>-<name>
  • Worktree dirs: .worktrees/issue-<build_id>-<NN>-<name>/

The cleanup path derivation (branch.replace("/", "-")) continues to map correctly to worktree directories since setup and cleanup use the same convention.

Files changed:

  • swe_af/app.py — generate build_id, pass to run_git_init and execute()
  • swe_af/execution/dag_executor.py — thread build_id through run_dag(), _init_dag_state(), _setup_worktrees()
  • swe_af/execution/schemas.py — add build_id field to DAGState
  • swe_af/prompts/git_init.py — instruct agent to use feature/<build_id>-<goal-slug>
  • swe_af/prompts/workspace.py — instruct agent to use issue/<build_id>-<NN>-<name> branch/dir names
  • swe_af/reasoners/execution_agents.py — pass build_id to git_init_task_prompt and workspace_setup_task_prompt

Test Plan

  • Single build: verify branch names still work normally (no regression)
  • Concurrent builds on same repo: verify each gets unique branches (issue/abc12345-01-name vs issue/def67890-01-name)
  • Verify cleanup correctly removes each build's namespaced worktrees
  • Verify execute() called directly without build_id falls back to old naming

🤖 Generated with Claude Code

AbirAbbas and others added 3 commits February 17, 2026 18:36
When two build() calls run simultaneously on the same repository, they
collide on shared git resources: the integration branch (feature/<slug>)
and issue branches/worktrees (issue/<NN>-<name>). The workspace setup
agent even deletes existing branches when they conflict, silently
destroying the other build's in-progress work.

Fix: generate a short build_id (8 hex chars) at the start of build() and
thread it through the entire pipeline so all per-build git resources are
uniquely namespaced:

- Integration branch: feature/<build_id>-<goal-slug>
- Issue branches:     issue/<build_id>-<NN>-<name>
- Worktree dirs:      .worktrees/issue-<build_id>-<NN>-<name>/

The cleanup path derivation (branch.replace("/", "-")) continues to map
correctly to worktree directories because setup and cleanup use the same
naming convention.

All new parameters default to "" for backward compatibility — builds
that call execute() directly without a build_id fall back to the
existing naming convention with no regressions.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Two bugs in the original implementation:

1. Per-level cleanup (dag_executor.py ~1154) derived branch names as
   `issue/<NN>-<name>` without build_id, so it tried to delete branches
   that didn't exist (build_id-namespaced builds create `issue/<bid>-<NN>-<name>`).
   Prefer `branch_name` already injected by _setup_worktrees; fall back to
   build_id-prefixed derivation otherwise.

2. Final cleanup sweep (dag_executor.py ~1333) had the same bug when
   constructing the list from dag_state.all_issues.

Also tighten the workspace SETUP_SYSTEM_PROMPT to explicitly document
both the plain and Build-ID-prefixed command formats and instruct the
agent to always follow the task's specified format.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@AbirAbbas AbirAbbas merged commit d0e6346 into main Feb 18, 2026
1 check passed
@AbirAbbas AbirAbbas deleted the fix/concurrent-build-isolation branch February 18, 2026 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant